package com.zis.starter.core;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.io.Serializable;

/**
 * Create by wangshen 2018/1/22
 */
public class ResponseEntity <T> implements Serializable {

    public static final int SUCCEED = 0;

    public static final int FAIL = -1;

    private int code;

    private T respData;

    public ResponseEntity () {

    }

    public ResponseEntity(int code, T respData) {
        this.code = code;
        this.respData = respData;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public T getRespData() {
        return respData;
    }

    public void setRespData(T respData) {
        this.respData = respData;
    }

    /**
     * 成功并返回文本消息
	 * @param msg
	 * @return
             */
    public static ResponseEntity success(String msg) {
        return new ResponseEntity<String>(ResponseEntity.SUCCEED, msg);
    }

    /**
     * 成功并返回JSON对象字符串
     * @param jsonObject
     * @return
     */
    public static ResponseEntity success(JSONObject jsonObject) {
        return new ResponseEntity<JSONObject>(ResponseEntity.SUCCEED, jsonObject);
    }

    /**
     * 成功并返回JSON数组字符串
     * @param jsonArray
     * @return
     */
    public static ResponseEntity success(JSONArray jsonArray) {
        return new ResponseEntity<JSONArray>(ResponseEntity.SUCCEED, jsonArray);
    }

    /**
     * 错误并返回消息
     * @param msg
     * @return
     */
    public static ResponseEntity failure(String msg) {
        return new ResponseEntity<String>(ResponseEntity.FAIL, msg);
    }

    /**
     * 错误并返回JSON对象字符串
     * @param jsonObject
     * @return
     */
    public static ResponseEntity failure(JSONObject jsonObject) {
        return new ResponseEntity<JSONObject>(ResponseEntity.FAIL, jsonObject);
    }

}
